<?php 
/**
 * @desc 邮件发送类
 * @package    Email
 * @author     chengtao
 */
class Email extends Think{
	private $PHPMailer;
	/*
	 * 构造函数
	 * @author chengtao
	 */
	public function __construct(){
		$this->init();
	}
	/*
	 * 发送邮件
	 * @author chengtao
	 * @param  string $to_email 发送的邮箱地址
	 * @param  string $content  发送的邮箱内容
	 * @param  string $subject  发送的邮箱标题
	 * @return bool   $flag     发送是否成功
	 */
	public function  send($to_email,$content,$subject){
		$this->PHPMailer->Subject = $subject;
		$this->PHPMailer->Body = $content; //邮件内容
		$this->PHPMailer->AddAddress($to_email, "");		
		return $this->PHPMailer->Send();
	}
	/*
	 * 初始化PHPMailer
	 * @author chengtao
	 */
	private function init(){
		import('@.ORG.PHPMailer.PHPMailer');
		C(array('email' => include('Conf/email.php')));
		$this->PHPMailer = new PHPMailer(); 
		$this->PHPMailer->IsSMTP();               
		$this->PHPMailer->Host = C('email.smtp_host');	//设置SMTP服务器地址
		if(C('email.smtp_port')){
			$this->PHPMailer->Port = C('email.smtp_port');	//设置SMTP服务器端口号
		}
		$this->PHPMailer->SMTPSecure = "ssl";                 // 安全协议
		$this->PHPMailer->SMTPAuth = true;         				//是否开启SMTP
		$this->PHPMailer->Username = C('email.from_email');	//发送的邮箱
		$this->PHPMailer->Password = C('email.password');		//邮箱密码
		$this->PHPMailer->From = C('email.from_email');		//邮箱
		$this->PHPMailer->FromName =  C('email.from_name');
		$this->PHPMailer->CharSet = "utf-8";  
		$this->PHPMailer->Encoding = "base64";
		$this->PHPMailer->IsHTML(true);  
	}
	/*
	 * 获取错误信息
	 * @author chengtao
	 * @return string 错误信息
	 */
	public function getError(){
		return $this->$PHPMailer->ErrorInfo;
	}
}
?>